package com.netty.modbus.dto.response;

import com.netty.modbus.exception.DataConvertException;
import com.netty.modbus.util.DateUtil;
import com.netty.modbus.util.HexUtil;
import io.netty.buffer.ByteBuf;

/**
 * description: DateTimeBody <br>
 * date: 2021/9/29 16:04 <br>
 * @author: lwy <br>
 * @version: 1.0 <br>
 */
public class DateTimeBody extends ResponseBody{
    private final int BYTE_LENGTH = 7;
    @Override
    public void decode(byte[] data) {
        this.commDecode(BYTE_LENGTH,data);
    }

    @Override
    public ByteBuf encode() throws DataConvertException {
        //获取当前时间
        String[] dateAry=new String[7];
        dateAry[0]=HexUtil.intToHexString(DateUtil.getCurrentYear()) ;
        dateAry[1]=HexUtil.intToHexString(DateUtil.getCurrentMonth());
        dateAry[2]=HexUtil.intToHexString(DateUtil.getCurrentDay());
        dateAry[3]=HexUtil.intToHexString(DateUtil.getCurrentWeek());
        dateAry[4]=HexUtil.intToHexString(DateUtil.getCurrentHours());
        dateAry[5]=HexUtil.intToHexString(DateUtil.getCurrentMinutes());
        dateAry[6]=HexUtil.intToHexString(DateUtil.getCurrentSeconds());
        byte[] data=HexUtil.strToByte(dateAry);
        return  this.commEncode(data);
    }
}
